<!DOCTYPE html>
<html lang="zh-cn">
<head>
{include file="public/header" /}
<script type="text/javascript" src="__HOUTAI__/js/ajaxfileupload.js"></script>

</head>
<body>
<div class="panel admin-panel margin-top">
  <div class="body-content">
    <form class="form-x" action="" id="banner-edit" name="cate-add">
    <input type="hidden" name="id" value="{$banneredit.id}" id="id">
      <div class="form-group">
        <div class="label">
          <label>图片：</label>
        </div>
        <style type="text/css">
          /*a  upload */
        .a-upload {
            padding: 10px 15px;
            line-height: 20px;
            position: relative;
            cursor: pointer;
            color: #888;
            background: #0ae;
            border: 1px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
            display: inline-block;
            *display: inline;
            *zoom: 1
        }

        .a-upload  input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        </style>
        <div class="field">
          <input type="text" name="img" class="input tips" style="width:25%; float:left;"  id="thumb" value="{$banneredit.thumb}" />
          <a href="javascript:;" class="a-upload button bg-blue margin-left"  style="float:left;">
              <input type="file" id="id_photos" name="id_photos" onchange="thumb_onchange(this);" title="{$banneredit.thumb}">+ 浏览上传
          </a>
          <img src="{$banneredit.thumb}" id="upimg" style="height: 42px; margin-left: 15px; float: left;">
          <div class="tipss">图片尺寸：500*500</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="{$banneredit.alt}" name="title" id="titleid" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>地址：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="{$banneredit.url}" name="url" id="urlid" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>显示：</label>
        </div>
        <div class="field">
          <div class="button-group radio">        
            <input id="isshow" name="sort" type="checkbox" {if condition="$banneredit.show==1"}checked{/if}>是否显示
           </div>       
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-feiji" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
function thumb_onchange(obj){
  $.ajaxFileUpload({
    url:"{:url('content/uploadimg')}",   //处理图片的脚本路径
    type: 'POST',       //提交的方式
    // data:thumb,
    secureuri :false,   //是否启用安全提交
    fileElementId :'id_photos',     //file控件ID
    dataType : 'JSON',  //服务器返回的数据类型 
    success : function (data){
      var data=eval("("+data+")");
      if(data.status)
      {
        $("#upimg").attr("src",data.filename);
        $("#thumb").val(data.filename);
        $("#id_photos").val();
      }
      else
      {
        // layer.alert(data.msg);
        alert('格式错误');
      }
    }
  });
};

$(function(){
  $('#banner-edit').validate({
    submitHandler:function(form){
      var alt= $("#titleid").val();//标题
      var url=$("#urlid").val();//图片链接地址
      var thumb=$("#thumb").val();//图片路径
      var isshow=$("input[type='checkbox']").is(':checked');//是否显示
      var id=$("#id").val();
      if(isshow){
        isshow=1;
      }else{
        isshow=0;
      };
      $.ajax({
        type:"POST",
        url:"{:url('banner/editajax')}",
        data:{
          'id':id,
          'alt':alt,
          'thumb':thumb,
          'show':isshow,
          'url':url,
        },
        success:function(data){
          var data=eval("("+data+")");
          if (data.status) {
            parent.layer.msg("图片修改成功！",{icon:1,time:1000,},function(){parent.location.reload();});
          }else{
            parent.layer.msg("图片修改失败！",{icon:2,time:1000});
          }

        }
      })
    }
  })
})
    
</script>
</body>
</html>